package com.cn.mmd.controller;

import com.cn.mmd.model.*;
import com.cn.mmd.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by Administrator on 2016/10/20.
 */
@Controller
@RequestMapping(value ="leadership")
public class LeadershipController {

    @Autowired
    LeadershipService leadershipService;
    @Autowired
    TokenController tokenController;
    @Autowired
    QuestionnaireService questionnaireService;
    @Autowired
    StudentService studentService;
    @Autowired
    CourseService courseService;
    @Autowired
    MajorCourseNumController majorCourseNumController;
    @Autowired
    EvaluateTeacherService evaluateTeacherService;
    @Autowired
    EmploymentService employmentService;
    @Autowired
    LabelService labelService;
    @Autowired
    EvaluateStaService evaluateStaService;

//    /**
//     *教师测评统计：全校统计
//     * @param request
//     * @return
//     */
//    @RequestMapping(value = "schoolEvaluateStatisticsTeacher")
//    public synchronized @ResponseBody
//    Map<String,Object> schoolEvaluateStatistics(HttpServletRequest request)throws Exception {
//
//        Map<String, Object> map = new HashMap<String, Object>();
//
////        String collegeName=request.getParameter("collegeName");//学院
//        String teacherId=request.getParameter("teacherId");//校长id
//        Integer roleId = Integer.parseInt(request.getParameter("roleId"));
//        String token=request.getParameter("token");
//        System.out.println(teacherId + "---" + roleId + "---" + token);
//
//        TeacherData teacherData;
//        teacherData = (TeacherData) tokenController.tokenLead(teacherId, roleId, token);
//        if (teacherData==null){
//            map.put("code", 202);
//            map.put("message", "您暂无权限做此操作");
//            map.put("data", null);
//            return map;
//        }
//
//        AvgSchool avgSchool= leadershipService.selectAvgSchool();
//        if (avgSchool!=null){
//
////            Map<String, Object> map1 = new HashMap<String, Object>();//这里要改！！！！！！！！！！！！！！！！！！！！！11
////            float schoolAvg=(float)(Math.round((avgSchool.getSchoolsum()/avgSchool.getSchoolheadcount()) * 100)) / 100;
////            float studentSchool=(float)(Math.round((avgSchool.getStudentschoolsum()/avgSchool.getStudentschoolheadcount()) * 100)) / 100;
////            float colleagueSchool=(float)(Math.round((avgSchool.getColleagueschoolsum()/avgSchool.getColleagueschoolheadcount()) * 100)) / 100;
////            float supervisorSchool=(float)(Math.round((avgSchool.getSupervisorschoolsum()/avgSchool.getSupervisorschoolheadcount()) * 100)) / 100;
////
////            map1.put("schoolAvg",schoolAvg);
////            map1.put("studentSchool",studentSchool);
////            map1.put("colleagueSchool",colleagueSchool);
////            map1.put("supervisorSchool",supervisorSchool);
//
//            map.put("code",200);
//            map.put("message","查询全校统计结果成功");
////            map.put("data",map1);、、！！！！！！！！！！！！！！！！！！！
//        }else {
//            map.put("code",201);
//            map.put("message","查询全校统计结果失败");
//            map.put("data",null);
//        }
//
//    return map;
//    }

    /**
     *教师测评学生评价统计概况
     * @param request
     * @return
     */
    @RequestMapping(value = "studentEvaluationProfile")
    public synchronized @ResponseBody
    Map<String,Object> studentEvaluationProfile(HttpServletRequest request)throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();

//        String statisticsType=request.getParameter("statisticsType");//统计类型  学生评价studentEvaluate或同行评价colleagueEvaluate或督导评价supervisorEvaluate
        String collegeName=request.getParameter("collegeName");//学院名  如果查看的是全校的，则学院名为空
        String teacherId=request.getParameter("teacherId");//领导id
        Integer roleId = Integer.parseInt(request.getParameter("roleId"));//角色
        String token=request.getParameter("token");

        TeacherData teacherData;
        teacherData = (TeacherData) tokenController.tokenLead(teacherId, roleId, token);
        if (teacherData==null){
            map.put("code", 203);
            map.put("message", "您暂无权限做此操作");
//            map.put("data", null);
            return map;
        }


        if (collegeName==null||collegeName.equals("")) {//对全校的查询

//            System.out.println("进来了：" + statisticsType);
            String stuTwoIndexScore="";
            AvgSchool avgSchool=leadershipService.selectAvgSchool();
            if (avgSchool!=null){
                if (avgSchool.getStutwoindexscore()!=null){
                    stuTwoIndexScore=avgSchool.getStutwoindexscore();
                }
            }

//            if (statisticsType.equals("studentEvaluate")) {//学生评
                Map<String, Object> map1 = new HashMap<String, Object>();
                Map<String, List<Map>> map3 = new HashMap<String, List<Map>>();
                Map<String,Object> map4=null;
                List<Map> mapList=new ArrayList<Map>();
//                System.out.println("进入学生评");
                if (!stuTwoIndexScore.equals("")) {
                    String[] stuTwoIndexScores = stuTwoIndexScore.split("!!");
                    for (String s : stuTwoIndexScores) {
                        String[] strings = s.split("_");
                        String twoIndexName = strings[0];//二级指标名
                        float twoIndexScore = (float) (Math.round(Float.parseFloat(strings[1]) / Float.parseFloat(strings[2]) * 100)) / 100;
                        map1.put(twoIndexName, twoIndexScore);//二级指标名：分数
                    }
                    LabelTwoIndex labelTwoIndex1 = new LabelTwoIndex();
                    labelTwoIndex1.setPackagelabel("教评");
                    List<LabelTwoIndex> labelTwoIndexList = labelService.selectBylabelName(labelTwoIndex1);
                    Map<String, Object> map2 = null;
                    if (labelTwoIndexList.size() > 0) {
                        for (LabelTwoIndex labelTwoIndex : labelTwoIndexList) {
                            map2 = new HashMap<String, Object>();
                            List<Map> mapList1 = new ArrayList<Map>();
                            if (map1.containsKey(labelTwoIndex.getTwoindexname())) {
                                map2.put("twoIndexName", labelTwoIndex.getTwoindexname());
                                map2.put("twoIndexScore", map1.get(labelTwoIndex.getTwoindexname()));

                                if (map3.containsKey(labelTwoIndex.getIndexname())) {
                                    map3.get(labelTwoIndex.getIndexname()).add(map2);

                                } else {
                                    mapList1.add(map2);
                                    map3.put(labelTwoIndex.getIndexname(), mapList1);
                                }
                            }
                        }
                    }
                    for (String key: map3.keySet()){
                        map4=new HashMap<String, Object>();
                        map4.put("indexName",key);
                        map4.put("twoIndexList",map3.get(key));
                        mapList.add(map4);
                    }

                    map.put("code", 200);
                    map.put("message", "查询学生评价统计结果成功");
                    map.put("data", mapList);
                }else {
                    map.put("code", 201);
                    map.put("message", "查询无学生评价统计");
                }
//            }
        }else {//学院查询

//            System.out.println("进来了：" + statisticsType);
            String stuTwoIndexScore="";
            AvgCollege avgCollege=leadershipService.selectAvgCollege(collegeName);
            if (avgCollege!=null){
                if (avgCollege.getStutwoindexscore()!=null){
                    stuTwoIndexScore=avgCollege.getStutwoindexscore();
                }
            }
//            if (statisticsType.equals("studentEvaluate")) {//学生评
                Map<String, Object> map1 = new HashMap<String, Object>();
                Map<String, List<Map>> map3 = new HashMap<String, List<Map>>();
                Map<String,Object> map4=null;
                List<Map> mapList=new ArrayList<Map>();
//                System.out.println("进入学生评");
                if (!stuTwoIndexScore.equals("")) {
                    String[] stuTwoIndexScores = stuTwoIndexScore.split("!!");
                    for (String s : stuTwoIndexScores) {
                        String[] strings = s.split("_");
                        String twoIndexName = strings[0];//二级指标名
                        float twoIndexScore = (float) (Math.round(Float.parseFloat(strings[1]) / Float.parseFloat(strings[2]) * 100)) / 100;
                        map1.put(twoIndexName, twoIndexScore);//二级指标名：分数
                    }
                    LabelTwoIndex labelTwoIndex1 = new LabelTwoIndex();
                    labelTwoIndex1.setPackagelabel("教评");
                    List<LabelTwoIndex> labelTwoIndexList = labelService.selectBylabelName(labelTwoIndex1);
                    Map<String, Object> map2 = null;
                    if (labelTwoIndexList.size() > 0) {
                        for (LabelTwoIndex labelTwoIndex : labelTwoIndexList) {
                            map2 = new HashMap<String, Object>();
                            List<Map> mapList1 = new ArrayList<Map>();
                            if (map1.containsKey(labelTwoIndex.getTwoindexname())) {
                                map2.put("twoIndexName", labelTwoIndex.getTwoindexname());
                                map2.put("twoIndexScore", map1.get(labelTwoIndex.getTwoindexname()));

                                if (map3.containsKey(labelTwoIndex.getIndexname())) {
                                    map3.get(labelTwoIndex.getIndexname()).add(map2);

                                } else {
                                    mapList1.add(map2);
                                    map3.put(labelTwoIndex.getIndexname(), mapList1);
                                }
                            }
                        }
                    }
                    for (String key: map3.keySet()){
                        map4=new HashMap<String, Object>();
                        map4.put("indexName",key);
                        map4.put("twoIndexList",map3.get(key));
                        mapList.add(map4);
                    }

                    map.put("code", 200);
                    map.put("message", "查询学生评价统计结果成功");
                    map.put("data", mapList);
                }else {

                    map.put("code", 201);
                    map.put("message", "查询无学生评价统计");
                }
//            }

        }
        return map;
    }


    /**
     *教师测评同事/督导评价统计概况
     * @param request
     * @return
     */
    @RequestMapping(value = "teacherEvaluationProfile")
    public synchronized @ResponseBody
    Map<String,Object> teacherEvaluationProfile(HttpServletRequest request)throws Exception {
//        System.out.println("进入接口！！！");
        Map<String, Object> map = new HashMap<String, Object>();
        String statisticsType=request.getParameter("statisticsType");//统计类型  学生评价studentEvaluate或同行评价colleagueEvaluate或督导评价supervisorEvaluate
        String collegeName=request.getParameter("collegeName");//学院名  如果查看的是全校的，则学院名为空
        String teacherId=request.getParameter("teacherId");//领导id
        Integer roleId = Integer.parseInt(request.getParameter("roleId"));//角色
        String token=request.getParameter("token");

        TeacherData teacherData;
        teacherData = (TeacherData) tokenController.tokenLead(teacherId, roleId, token);
        if (teacherData==null){
            map.put("code", 203);
            map.put("message", "您暂无权限做此操作");
//            map.put("data", null);
            return map;
        }

        if (collegeName==null||collegeName.equals("")) {//对全校的查询

//            System.out.println("进来了：" + statisticsType);
            String collTwoIndexScore = "", supTwoIndexScore = "";
            AvgSchool avgSchool = leadershipService.selectAvgSchool();
            if (avgSchool != null) {
                if (avgSchool.getColltwoindexscore() != null) {
                    collTwoIndexScore = avgSchool.getColltwoindexscore();
                }
                if (avgSchool.getSuptwoindexscore() != null) {
                    supTwoIndexScore = avgSchool.getSuptwoindexscore();
                }
            }
//            System.out.println("同行评价："+collTwoIndexScore+"----督导评价："+supTwoIndexScore);
            if (statisticsType.equals("colleagueEvaluate")) {//同行评

                List<LabelTwoIndex> labelTwoIndexList = new ArrayList<LabelTwoIndex>();
                List<Map> mapList = new ArrayList<Map>();
//                System.out.println("进入同行评");
                if (!collTwoIndexScore.equals("")) {

                    String[] collTwoIndexScores = collTwoIndexScore.split("!!");

                    LabelTwoIndex labelTwoIndex = null;
                    for (String s : collTwoIndexScores) {

                        labelTwoIndex = new LabelTwoIndex();
                        String[] s1 = s.split("_");
                        String twoIndexName = s1[0];//二级指标名
                        float twoIndexScore = Float.parseFloat(s1[1]) / Float.parseFloat(s1[2]);//二级指标得分
                        labelTwoIndex.setTwoindexname(twoIndexName);

                        List<LabelTwoIndex> labelTwoIndexList1 = labelService.selectBylabelName(labelTwoIndex);

//                        System.out.println("同事评价二级指标："+twoIndexName+"   查出来？？"+labelTwoIndexList1);
                        labelTwoIndexList1.get(0).setTwoindexscore(twoIndexScore);

                        labelTwoIndexList.add(labelTwoIndexList1.get(0));//把所有二级指标放入对象中再存入list里
                    }
                    Map<String, Object> map2 = null;
                    for (int a = 0; a < labelTwoIndexList.size(); a++) {
                        map2 = new HashMap<String, Object>();
                        List<Float> scores = new ArrayList<Float>();
                        List<String> twoIndexNames = new ArrayList<String>();
                        for (int b = labelTwoIndexList.size() - 1; b > a; b--) {
                            if (labelTwoIndexList.get(a).getIndexname().equals(labelTwoIndexList.get(b).getIndexname())) {

//                                float score1 = (float) (Math.round(labelTwoIndexList.get(b).getTwoindexscore() * labelTwoIndexList.get(b).getProportion() * 100)) / 100;
                                float score1=labelTwoIndexList.get(b).getTwoindexscore() * labelTwoIndexList.get(b).getProportion();
                                scores.add(score1);
                                twoIndexNames.add(labelTwoIndexList.get(b).getTwoindexname());
                                labelTwoIndexList.remove(b);
                            }
                        }
//                        float score1 = (float) (Math.round(labelTwoIndexList.get(a).getTwoindexscore() * labelTwoIndexList.get(a).getProportion() * 100)) / 100;
                        float score1=labelTwoIndexList.get(a).getTwoindexscore() * labelTwoIndexList.get(a).getProportion();
                        scores.add(score1);
                        twoIndexNames.add(labelTwoIndexList.get(a).getTwoindexname());

                        float sun = 0f;
                        for (float f : scores) {
//                            System.out.print(f+"  +  ");
                            sun += f;
                        }
//                        System.out.println("和1：" + sun);
                        sun=(float)(Math.round(sun*100))/100;
//                        System.out.println("和2：" + sun);
                        map2.put("indexName", labelTwoIndexList.get(a).getIndexname());//一级指标名
                        map2.put("indexScore", sun);//一级指标得分
                        map2.put("twoIndexList", twoIndexNames);//所属的二级指标list

                        mapList.add(map2);
                    }

                    map.put("code", 200);
                    map.put("message", "查询同行评价统计结果成功");
                    map.put("data", mapList);

                } else {

                    String packageName = "教评";
                    Map<String, Object> map1 = null;
                    List<String> stringList = null;
                    List<LabelIndex> labelIndexList = labelService.selectByPackageName(packageName);
                    for (LabelIndex labelIndex : labelIndexList) {
                        if (labelIndex.getIndexid() != 5) {//不要对学校评价的那个一级指标
                            stringList=new ArrayList<String>();
                            LabelTwoIndex labelTwoIndex = new LabelTwoIndex();
                            labelTwoIndex.setIndexname(labelIndex.getIndexname());
                            List<LabelTwoIndex> labelTwoIndexList1 = labelService.selectBylabelName(labelTwoIndex);//查到二级指标
//                            System.out.println("查到多少个："+labelTwoIndexList1.size());
                            for (LabelTwoIndex labelTwoIndex1 : labelTwoIndexList1) {
                                stringList.add(labelTwoIndex1.getTwoindexname());
                            }
                            map1 = new HashMap<String, Object>();
                            map1.put("indexName", labelIndex.getIndexname());//一级指标名
                            map1.put("indexScore", 0);// 一级指标得分
                            map1.put("twoIndexList", stringList);//所属的二级指标list

                            mapList.add(map1);
                        }
                    }

                    map.put("code", 200);
                    map.put("message", "查询无同行评价统计");
                    map.put("data", mapList);

//                    map.put("code", 201);
//                    map.put("message", "查询无同行评价统计");
                }

            } else if (statisticsType.equals("supervisorEvaluate")) {//督导评

//                System.out.println("进入督导评");
                List<LabelTwoIndex> labelTwoIndexList = new ArrayList<LabelTwoIndex>();
                List<Map> mapList = new ArrayList<Map>();
                if (!supTwoIndexScore.equals("")) {

                    String[] supTwoIndexScores = supTwoIndexScore.split("!!");
                    LabelTwoIndex labelTwoIndex = null;
                    for (String s : supTwoIndexScores) {

                        labelTwoIndex = new LabelTwoIndex();
                        String[] s1 = s.split("_");
                        String twoIndexName = s1[0];//二级指标名
                        float twoIndexScore = Float.parseFloat(s1[1]) / Float.parseFloat(s1[2]);//二级指标得分
                        labelTwoIndex.setTwoindexname(twoIndexName);

                        List<LabelTwoIndex> labelTwoIndexList1 = labelService.selectBylabelName(labelTwoIndex);

//                        System.out.println("督导评价二级指标："+twoIndexName);
                        labelTwoIndexList1.get(0).setTwoindexscore(twoIndexScore);

                        labelTwoIndexList.add(labelTwoIndexList1.get(0));//把所有二级指标放入对象中再存入list里
                    }
                    Map<String, Object> map2 = null;
                    for (int a = 0; a < labelTwoIndexList.size(); a++) {
                        map2 = new HashMap<String, Object>();
                        List<Float> scores = new ArrayList<Float>();
                        List<String> twoIndexNames = new ArrayList<String>();
                        for (int b = labelTwoIndexList.size() - 1; b > a; b--) {
                            if (labelTwoIndexList.get(a).getIndexname().equals(labelTwoIndexList.get(b).getIndexname())) {

//                                float score1 = (float) (Math.round(labelTwoIndexList.get(b).getTwoindexscore() * labelTwoIndexList.get(b).getProportion() * 100)) / 100;
                                float score1=labelTwoIndexList.get(b).getTwoindexscore() * labelTwoIndexList.get(b).getProportion();
                                scores.add(score1);
                                twoIndexNames.add(labelTwoIndexList.get(b).getTwoindexname());
                                labelTwoIndexList.remove(b);
                            }
                        }
//                        float score1 = (float) (Math.round(labelTwoIndexList.get(a).getTwoindexscore() * labelTwoIndexList.get(a).getProportion() * 100)) / 100;
                        float score1=labelTwoIndexList.get(a).getTwoindexscore() * labelTwoIndexList.get(a).getProportion();
                        scores.add(score1);
                        twoIndexNames.add(labelTwoIndexList.get(a).getTwoindexname());

                        float sun = 0f;
                        for (float f : scores) {
                            sun += f;
                        }
                        sun=(float)(Math.round(sun*100))/100;
                        map2.put("indexName", labelTwoIndexList.get(a).getIndexname());//一级指标名
                        map2.put("indexScore", sun);//一级指标得分
                        map2.put("twoIndexList", twoIndexNames);//所属的二级指标list

                        mapList.add(map2);
                    }

                    map.put("code", 200);
                    map.put("message", "查询督导评价统计成功");
                    map.put("data", mapList);

                } else {
                    String packageName = "教评";
                    Map<String, Object> map1 = null;
                    List<String> stringList = null;
                    List<LabelIndex> labelIndexList = labelService.selectByPackageName(packageName);
                    for (LabelIndex labelIndex : labelIndexList) {
                        if (labelIndex.getIndexid() != 5) {//不要对学校评价的那个一级指标
                            stringList=new ArrayList<String>();
                            LabelTwoIndex labelTwoIndex = new LabelTwoIndex();
                            labelTwoIndex.setIndexname(labelIndex.getIndexname());
                            List<LabelTwoIndex> labelTwoIndexList1 = labelService.selectBylabelName(labelTwoIndex);//查到二级指标
//                            System.out.println("查到多少个？"+labelTwoIndexList1.size());
                            for (LabelTwoIndex labelTwoIndex1 : labelTwoIndexList1) {
                                stringList.add(labelTwoIndex1.getTwoindexname());
                            }
                            map1 = new HashMap<String, Object>();
                            map1.put("indexName", labelIndex.getIndexname());//一级指标名
                            map1.put("indexScore", 0);// 一级指标得分
                            map1.put("twoIndexList", stringList);//所属的二级指标list

                            mapList.add(map1);
                        }
                    }

                    map.put("code", 200);
                    map.put("message", "查询无督导评价统计");
                    map.put("data", mapList);
//                    map.put("code", 201);
//                    map.put("message", "查询无督导评价统计");
                }

            } else {
                map.put("code", 202);
                map.put("message", "传入评价类型错误");
//                map.put("data", null);
            }

        }else {
//          学院评价：
            String collTwoIndexScore="",supTwoIndexScore="";
            AvgCollege avgCollege=leadershipService.selectAvgCollege(collegeName);
            if (avgCollege!=null){
                if (avgCollege.getColltwoindexscore()!=null){
                    collTwoIndexScore=avgCollege.getColltwoindexscore();
                }
                if (avgCollege.getSuptwoindexscore()!=null){
                    supTwoIndexScore=avgCollege.getSuptwoindexscore();
                }
            }

            if (statisticsType.equals("colleagueEvaluate")) {//同行评

                List<LabelTwoIndex> labelTwoIndexList = new ArrayList<LabelTwoIndex>();
                List<Map> mapList = new ArrayList<Map>();
//                System.out.println("进入同行评");
                if (!collTwoIndexScore.equals("")) {

                    String[] collTwoIndexScores = collTwoIndexScore.split("!!");
                    LabelTwoIndex labelTwoIndex = null;
                    for (String s : collTwoIndexScores) {

                        labelTwoIndex = new LabelTwoIndex();
                        String[] s1 = s.split("_");
                        String twoIndexName = s1[0];//二级指标名
                        float twoIndexScore = Float.parseFloat(s1[1]) / Float.parseFloat(s1[2]);//二级指标得分
                        labelTwoIndex.setTwoindexname(twoIndexName);

                        List<LabelTwoIndex> labelTwoIndexList1 = labelService.selectBylabelName(labelTwoIndex);

                        labelTwoIndexList1.get(0).setTwoindexscore(twoIndexScore);

                        labelTwoIndexList.add(labelTwoIndexList1.get(0));//把所有二级指标放入对象中再存入list里
                    }
                    Map<String, Object> map2 = null;
                    for (int a = 0; a < labelTwoIndexList.size(); a++) {
                        map2 = new HashMap<String, Object>();
                        List<Float> scores = new ArrayList<Float>();
                        List<String> twoIndexNames = new ArrayList<String>();
                        for (int b = labelTwoIndexList.size() - 1; b > a; b--) {
                            if (labelTwoIndexList.get(a).getIndexname().equals(labelTwoIndexList.get(b).getIndexname())) {

//                                float score1 = (float) (Math.round(labelTwoIndexList.get(b).getTwoindexscore() * labelTwoIndexList.get(b).getProportion() * 100)) / 100;
                                float score1=labelTwoIndexList.get(b).getTwoindexscore() * labelTwoIndexList.get(b).getProportion();
                                scores.add(score1);
                                twoIndexNames.add(labelTwoIndexList.get(b).getTwoindexname());
                                labelTwoIndexList.remove(b);
                            }
                        }
//                        float score1 = (float) (Math.round(labelTwoIndexList.get(a).getTwoindexscore() * labelTwoIndexList.get(a).getProportion() * 100)) / 100;
                        float score1=labelTwoIndexList.get(a).getTwoindexscore() * labelTwoIndexList.get(a).getProportion();
                        scores.add(score1);
                        twoIndexNames.add(labelTwoIndexList.get(a).getTwoindexname());

                        float sun = 0f;
                        for (float f : scores) {
                            sun += f;
                        }
                        sun=(float)(Math.round(sun*100))/100;
                        map2.put("indexName", labelTwoIndexList.get(a).getIndexname());//一级指标名
                        map2.put("indexScore", sun);//一级指标得分
                        map2.put("twoIndexList", twoIndexNames);//所属的二级指标list

                        mapList.add(map2);
                    }

                    map.put("code", 200);
                    map.put("message", "查询同行评价统计成功");
                    map.put("data", mapList);

                } else {
                    String packageName = "教评";
                    Map<String, Object> map5 = null;
                    List<String> stringList = null;
                    List<LabelIndex> labelIndexList = labelService.selectByPackageName(packageName);
                    for (LabelIndex labelIndex : labelIndexList) {
                        if (labelIndex.getIndexid() != 5) {//不要对学校评价的那个一级指标
                            stringList = new ArrayList<String>();
                            LabelTwoIndex labelTwoIndex = new LabelTwoIndex();
                            labelTwoIndex.setIndexname(labelIndex.getIndexname());
                            List<LabelTwoIndex> labelTwoIndexList1 = labelService.selectBylabelName(labelTwoIndex);//查到二级指标
                            for (LabelTwoIndex labelTwoIndex1 : labelTwoIndexList1) {

                                stringList.add(labelTwoIndex1.getTwoindexname());
                            }
                            map5 = new HashMap<String, Object>();
                            map5.put("indexName", labelIndex.getIndexname());//一级指标名
                            map5.put("indexScore", 0);// 一级指标得分
                            map5.put("twoIndexList", stringList);//所属的二级指标list

                            mapList.add(map5);
                        }
                    }

                    map.put("code", 200);
                    map.put("message", "查询无督导评价统计");
                    map.put("data", mapList);
                }
            } else if (statisticsType.equals("supervisorEvaluate")) {//同行评

                List<LabelTwoIndex> labelTwoIndexList = new ArrayList<LabelTwoIndex>();
                List<Map> mapList = new ArrayList<Map>();
//                System.out.println("进入同行评");
                if (!supTwoIndexScore.equals("")) {

                    String[] supTwoIndexScores = supTwoIndexScore.split("!!");
                    LabelTwoIndex labelTwoIndex = null;
                    for (String s : supTwoIndexScores) {

                        labelTwoIndex = new LabelTwoIndex();
                        String[] s1 = s.split("_");
                        String twoIndexName = s1[0];//二级指标名
                        float twoIndexScore = Float.parseFloat(s1[1]) / Float.parseFloat(s1[2]);//二级指标得分
                        labelTwoIndex.setTwoindexname(twoIndexName);

                        List<LabelTwoIndex> labelTwoIndexList1 = labelService.selectBylabelName(labelTwoIndex);

                        labelTwoIndexList1.get(0).setTwoindexscore(twoIndexScore);

                        labelTwoIndexList.add(labelTwoIndexList1.get(0));//把所有二级指标放入对象中再存入list里
                    }
                    Map<String, Object> map2 = null;
                    for (int a = 0; a < labelTwoIndexList.size(); a++) {
                        map2 = new HashMap<String, Object>();
                        List<Float> scores = new ArrayList<Float>();
                        List<String> twoIndexNames = new ArrayList<String>();
                        for (int b = labelTwoIndexList.size() - 1; b > a; b--) {
                            if (labelTwoIndexList.get(a).getIndexname().equals(labelTwoIndexList.get(b).getIndexname())) {

//                                float score1 = (float) (Math.round(labelTwoIndexList.get(b).getTwoindexscore() * labelTwoIndexList.get(b).getProportion() * 100)) / 100;
                                float score1=labelTwoIndexList.get(b).getTwoindexscore() * labelTwoIndexList.get(b).getProportion();
                                scores.add(score1);
                                twoIndexNames.add(labelTwoIndexList.get(b).getTwoindexname());
                                labelTwoIndexList.remove(b);
                            }
                        }
//                        float score1 = (float) (Math.round(labelTwoIndexList.get(a).getTwoindexscore() * labelTwoIndexList.get(a).getProportion() * 100)) / 100;
                        float score1=labelTwoIndexList.get(a).getTwoindexscore() * labelTwoIndexList.get(a).getProportion();
                        scores.add(score1);
                        twoIndexNames.add(labelTwoIndexList.get(a).getTwoindexname());

                        float sun = 0f;
                        for (float f : scores) {
                            sun += f;
                        }
                        sun=(float)(Math.round(sun*100))/100;
                        map2.put("indexName", labelTwoIndexList.get(a).getIndexname());//一级指标名
                        map2.put("indexScore", sun);//一级指标得分
                        map2.put("twoIndexList", twoIndexNames);//所属的二级指标list

                        mapList.add(map2);
                    }

                    map.put("code", 200);
                    map.put("message", "查询同行评价统计成功");
                    map.put("data", mapList);

                } else {
                    String packageName = "教评";
                    Map<String, Object> map5 = null;
                    List<String> stringList = null;
                    List<LabelIndex> labelIndexList = labelService.selectByPackageName(packageName);
                    for (LabelIndex labelIndex : labelIndexList) {
                        if (labelIndex.getIndexid() != 5) {//不要对学校评价的那个一级指标
                            stringList = new ArrayList<String>();
                            LabelTwoIndex labelTwoIndex = new LabelTwoIndex();
                            labelTwoIndex.setIndexname(labelIndex.getIndexname());
                            List<LabelTwoIndex> labelTwoIndexList1 = labelService.selectBylabelName(labelTwoIndex);//查到二级指标
                            for (LabelTwoIndex labelTwoIndex1 : labelTwoIndexList1) {

                                stringList.add(labelTwoIndex1.getTwoindexname());
                            }
                            map5 = new HashMap<String, Object>();
                            map5.put("indexName", labelIndex.getIndexname());//一级指标名
                            map5.put("indexScore", 0);// 一级指标得分
                            map5.put("twoIndexList", stringList);//所属的二级指标list

                            mapList.add(map5);
                        }
                    }

                    map.put("code", 200);
                    map.put("message", "查询无督导评价统计");
                    map.put("data", mapList);
                }
            } else {
                map.put("code", 202);
                map.put("message", "传入评价类型错误");
            }
        }
            return map;
    }



    /**
     *查看学生评价二级指标详情
     * @param request
     * @return
     */
    @RequestMapping(value = "studentEvaluationTwoIndex")
    public synchronized @ResponseBody
    Map<String,Object> studentEvaluationTwoIndex(HttpServletRequest request)throws Exception {
        Map<String,Object> map=new HashMap<String, Object>();
        Map<String,Object> map1=null;
        List<Map> mapList=new ArrayList<Map>();

        String collegeName=request.getParameter("collegeName");//学院名 如果查的是全校，则为空
        String twoIndexName=request.getParameter("twoIndexName");//要查看的二级指标名

        String teacherId=request.getParameter("teacherId");//领导id
        Integer roleId = Integer.parseInt(request.getParameter("roleId"));//角色
        String token=request.getParameter("token");

        TeacherData teacherData;
        teacherData = (TeacherData) tokenController.tokenLead(teacherId, roleId, token);
        if (teacherData==null){
            map.put("code", 202);
            map.put("message", "您暂无权限做此操作");
//            map.put("data", null);
            return map;
        }

        if (collegeName==null||collegeName.equals("")){//没有学院名  查的是全校
            AvgSchool avgSchool= leadershipService.selectAvgSchool();
            String schoolName=avgSchool.getSchoolid();//学校名

            MonthStatistics monthStatistics=new MonthStatistics();
            monthStatistics.setStatisticalobject(schoolName);

            List<MonthStatistics> monthStatisticsList=evaluateStaService.selectByCondition(monthStatistics);
            if (monthStatisticsList.size()>0){
                for (MonthStatistics monthStatistics1:monthStatisticsList){

                    map1=new HashMap<String, Object>();
                    String theMonth=monthStatistics1.getStatisticsthemonth();//统计的月份
                    String statisticsResultMonth=monthStatistics1.getStatisticsresultmonth();//当月的统计得分

                    map1.put("theMonth",theMonth);
                    map1.put("twoIndexName",twoIndexName);

                    if (statisticsResultMonth.contains(twoIndexName)){
//                        String s="课程设置_7.0_2!!教学内容_15.0_3!!教学方法_5.0_1!!教学管理_19.5_5";
//                        String s1="课程设置";
                        String s2=statisticsResultMonth.split(twoIndexName+"_")[1];

                        if(s2.contains("!!")){
                            String s3=s2.split("!!")[0];
                            String[] s4=s3.split("_");
                            float score=(float)(Math.round(Float.parseFloat(s4[0])/Integer.parseInt(s4[1])*100))/100;//得分
//                            System.out.print(score);
                            map1.put("twoIndexScore",score);

                        }else {
                            String[] s4=s2.split("_");
                            float score=(float)(Math.round(Float.parseFloat(s4[0])/Integer.parseInt(s4[1])*100))/100;//得分
//                            System.out.print(score);
                            map1.put("twoIndexScore",score);
                        }
                    }else {
                        map1.put("twoIndexScore",0);
                    }

                    mapList.add(map1);
                }
                map.put("code", 200);
                map.put("message", "查询学生评价二级指标成功");
                map.put("data", mapList);
            }else {
                map.put("code", 201);
                map.put("message", "查询无学生评价二级指标");
//                map.put("data", mapList);
            }

        }else {

            MonthStatistics monthStatistics=new MonthStatistics();
            monthStatistics.setStatisticalobject(collegeName);

            List<MonthStatistics> monthStatisticsList=evaluateStaService.selectByCondition(monthStatistics);
            if (monthStatisticsList.size()>0){
                for (MonthStatistics monthStatistics1:monthStatisticsList){

                    map1=new HashMap<String, Object>();
                    String theMonth=monthStatistics1.getStatisticsthemonth();//统计的月份
                    String statisticsResultMonth=monthStatistics1.getStatisticsresultmonth();//当月的统计得分

                    map1.put("theMonth",theMonth);
                    map1.put("twoIndexName",twoIndexName);

                    if (statisticsResultMonth.contains(twoIndexName)){
//                        String s="课程设置_7.0_2!!教学内容_15.0_3!!教学方法_5.0_1!!教学管理_19.5_5";
//                        String s1="课程设置";
                        String s2=statisticsResultMonth.split(twoIndexName+"_")[1];

                        if(s2.contains("!!")){
                            String s3=s2.split("!!")[0];
                            String[] s4=s3.split("_");
                            float score=(float)(Math.round(Float.parseFloat(s4[0])/Integer.parseInt(s4[1])*100))/100;//得分
//                            System.out.print(score);
                            map1.put("twoIndexScore",score);

                        }else {
                            String[] s4=s2.split("_");
                            float score=(float)(Math.round(Float.parseFloat(s4[0])/Integer.parseInt(s4[1])*100))/100;//得分
//                            System.out.print(score);
                            map1.put("twoIndexScore",score);
                        }
                    }else {
                        map1.put("twoIndexScore",0);
                    }

                    mapList.add(map1);
                }
                map.put("code", 200);
                map.put("message", "查询学生评价二级指标成功");
                map.put("data", mapList);
            }else {
                map.put("code", 201);
                map.put("message", "查询无学生评价二级指标");
            }
        }
        return map;
    }


    /**
     *教师测评统计：学院统计
     * @param request
     * @return
     */
    @RequestMapping(value = "teacherEvaluationTwoIndex")
    public synchronized @ResponseBody
    Map<String,Object> teacherEvaluationTwoIndex(HttpServletRequest request)throws Exception {

        Map<String,Object> map=new HashMap<String, Object>();

        String statisticsType=request.getParameter("statisticsType");//统计类型  同行评价colleagueEvaluate或督导评价supervisorEvaluate
        String collegeName=request.getParameter("collegeName");//学院名 如果查的是全校，则为空
        String indexName=request.getParameter("indexName");//要查看的一级指标名

        String teacherId=request.getParameter("teacherId");//领导id
        Integer roleId = Integer.parseInt(request.getParameter("roleId"));//角色
        String token=request.getParameter("token");

        TeacherData teacherData;
        teacherData = (TeacherData) tokenController.tokenLead(teacherId, roleId, token);
        if (teacherData==null){
                map.put("code", 204);
            map.put("message", "您暂无权限做此操作");
//            map.put("data", null);
            return map;
        }

        List<String> stringList=new ArrayList<String>();
        LabelTwoIndex labelTwoIndex=new LabelTwoIndex();
        labelTwoIndex.setIndexname(indexName);
        List<LabelTwoIndex> labelTwoIndexList=labelService.selectBylabelName(labelTwoIndex);
        if (labelTwoIndexList.size()>0){
            for (LabelTwoIndex labelTwoIndex1:labelTwoIndexList){
                stringList.add(labelTwoIndex1.getTwoindexname());
            }
        }else{
            map.put("code", 201);
            map.put("message", "一级指标名传入错误");
            return map;
        }

        if(collegeName==null||collegeName.equals("")){//学院名为空  查全校
//            System.out.println("进入学校评价："+collegeName);
            String collTwoIndexScore = "", supTwoIndexScore = "";
            AvgSchool avgSchool = leadershipService.selectAvgSchool();
            if (avgSchool != null) {
                if (avgSchool.getColltwoindexscore() != null) {
                    collTwoIndexScore = avgSchool.getColltwoindexscore();
                }
                if (avgSchool.getSuptwoindexscore() != null) {
                    supTwoIndexScore = avgSchool.getSuptwoindexscore();
                }

                if (statisticsType.equals("colleagueEvaluate")) {//同行评价
                    Map<String,Object> map1=null;
                    Map<String,Object> map2=new HashMap<String, Object>();
                    List<Map> mapList=new ArrayList<Map>();
                    List<Float> floatList=new ArrayList<Float>();
                    String[] collTwoIndexScores=collTwoIndexScore.split("!!");
                    for (String s:collTwoIndexScores){
                        map1=new HashMap<String, Object>();
                        String [] strings=s.split("_");
                        String twoIndexName=strings[0];//二级指标名
                        if (stringList.contains(twoIndexName)){
                            float score=(float)(Math.round(Float.parseFloat(strings[1])/Integer.parseInt(strings[2])*100))/100;

                            map1.put("twoIndexName",twoIndexName);
                            map1.put("twoIndexScore",score);
                            mapList.add(map1);
                            floatList.add(score);
                        }
                    }
                    float score=0f;
                    if (floatList.size()>0) {
                        float sum = 0f;
                        for (float f : floatList) {
                            sum += f;
                        }
                        score=(float)(Math.round(sum/floatList.size()*100))/100;
                    }
                    map2.put("twoIndexList",mapList);
                    map2.put("twoIndexAvg",score);

                    map.put("code",200);
                    map.put("message","查询同事评价二级指标结果成功");
                    map.put("data",map2);
                }else if (statisticsType.equals("supervisorEvaluate")){//督导评价

                    Map<String,Object> map1=null;
                    Map<String,Object> map2=new HashMap<String, Object>();
                    List<Map> mapList=new ArrayList<Map>();
                    List<Float> floatList=new ArrayList<Float>();
                    String[] supTwoIndexScores=supTwoIndexScore.split("!!");
                    for (String s:supTwoIndexScores){
                        map1=new HashMap<String, Object>();
                        String [] strings=s.split("_");
                        String twoIndexName=strings[0];//二级指标名
                        if (stringList.contains(twoIndexName)){
                            float score=(float)(Math.round(Float.parseFloat(strings[1])/Integer.parseInt(strings[2])*100))/100;

                            map1.put("twoIndexName",twoIndexName);
                            map1.put("twoIndexScore",score);
                            mapList.add(map1);
                            floatList.add(score);
                        }
                    }
                    float score=0f;
                    if (floatList.size()>0) {
                        float sum = 0f;
                        for (float f : floatList) {
                            sum += f;
                        }
                        score=(float)(Math.round(sum/floatList.size()*100))/100;
                    }
                    map2.put("twoIndexList",mapList);
                    map2.put("twoIndexAvg",score);

                    map.put("code",200);
                    map.put("message","查询督导评价二级指标结果成功");
                    map.put("data",map2);
                }else {
                    map.put("code",203);
                    map.put("message","评价类型传入错误");
                }

            }else {
                map.put("code",202);
                map.put("message","学校查无数据");
            }

        }else {//查学院
//            System.out.println("进入学院评价-----："+collegeName);
            String collTwoIndexScore="",supTwoIndexScore="";
            AvgCollege avgCollege=leadershipService.selectAvgCollege(collegeName);
            if (avgCollege!=null) {
                if (avgCollege.getColltwoindexscore()!=null){
                    collTwoIndexScore=avgCollege.getColltwoindexscore();
                }
                if (avgCollege.getSuptwoindexscore()!=null){
                    supTwoIndexScore=avgCollege.getSuptwoindexscore();
                }

                if (statisticsType.equals("colleagueEvaluate")) {//同行评价
                    Map<String,Object> map1=null;
                    Map<String,Object> map2=new HashMap<String, Object>();
                    List<Map> mapList=new ArrayList<Map>();
                    List<Float> floatList=new ArrayList<Float>();
                    String[] collTwoIndexScores=collTwoIndexScore.split("!!");
                    for (String s:collTwoIndexScores){
                        map1=new HashMap<String, Object>();
                        String [] strings=s.split("_");
                        String twoIndexName=strings[0];//二级指标名
                        if (stringList.contains(twoIndexName)){
                            float score=(float)(Math.round(Float.parseFloat(strings[1])/Integer.parseInt(strings[2])*100))/100;

                            map1.put("twoIndexName",twoIndexName);
                            map1.put("twoIndexScore",score);
                            mapList.add(map1);
                            floatList.add(score);
                        }
                    }
                    float score=0f;
                    if (floatList.size()>0) {
                        float sum = 0f;
                        for (float f : floatList) {
                            sum += f;
                        }
                        score=(float)(Math.round(sum/floatList.size()*100))/100;
                    }
                    map2.put("twoIndexList",mapList);
                    map2.put("twoIndexAvg",score);

                    map.put("code",200);
                    map.put("message","查询同事评价二级指标结果成功");
                    map.put("data",map2);

                }else if (statisticsType.equals("supervisorEvaluate")){//督导评价

                    Map<String,Object> map1=null;
                    Map<String,Object> map2=new HashMap<String, Object>();
                    List<Map> mapList=new ArrayList<Map>();
                    List<Float> floatList=new ArrayList<Float>();
                    String[] supTwoIndexScores=supTwoIndexScore.split("!!");
                    for (String s:supTwoIndexScores){
                        map1=new HashMap<String, Object>();
                        String [] strings=s.split("_");
                        String twoIndexName=strings[0];//二级指标名
                        if (stringList.contains(twoIndexName)){
                            float score=(float)(Math.round(Float.parseFloat(strings[1])/Integer.parseInt(strings[2])*100))/100;

                            map1.put("twoIndexName",twoIndexName);
                            map1.put("twoIndexScore",score);
                            mapList.add(map1);
                            floatList.add(score);
                        }
                    }
                    float score=0f;
                    if (floatList.size()>0) {
                        float sum = 0f;
                        for (float f : floatList) {
                            sum += f;
                        }
                        score=(float)(Math.round(sum/floatList.size()*100))/100;
                    }
                    map2.put("twoIndexList",mapList);
                    map2.put("twoIndexAvg",score);

                    map.put("code",200);
                    map.put("message","查询督导评价二级指标结果成功");
                    map.put("data",map2);
                }else {
                    map.put("code",203);
                    map.put("message","评价类型传入错误");
                }
            }else {
                map.put("code",202);
                map.put("message","学院查无数据");
            }
        }
    return map;
    }
//
//
//
//    /**
//     *教师测评统计：学院统计详情
//     * @param request
//     * @return
//     */
//    @RequestMapping(value = "collegeEvaluateParticularsTeacher")
//    public synchronized @ResponseBody
//    Map<String,Object> collegeEvaluateParticulars(HttpServletRequest request)throws Exception {
//
//        Map<String, Object> map = new HashMap<String, Object>();
//
//        String collegeName=request.getParameter("collegeName");//学院名
//        String statisticsType=request.getParameter("statisticsType");//统计类型  学生评价studentEvaluate或同行评价colleagueEvaluate或督导评价supervisorEvaluate
//        String teacherId=request.getParameter("teacherId");
//        Integer roleId = Integer.parseInt(request.getParameter("roleId"));
//        String token=request.getParameter("token");
//
//        TeacherData teacherData;
//        teacherData = (TeacherData) tokenController.tokenLead(teacherId, roleId, token);
//        if (teacherData==null){
//            map.put("code", 202);
//            map.put("message", "您暂无权限做此操作");
//            map.put("data", null);
//            return map;
//        }
//
//        if (statisticsType.equals("studentEvaluate")){//学生评
//
//            System.out.println("进入学生评");
//            StudentEvaluate studentEvaluate=new StudentEvaluate();
//            studentEvaluate.setColleaguename(collegeName);
//            List<StudentEvaluate> studentEvaluateList=leadershipService.selectAllStudentEvaluate(studentEvaluate);
//            Map<String,Float> map1=null;
//            List<Map> mapList=new ArrayList<Map>();
//            System.out.println("查出来的长度："+studentEvaluateList.size());
//            if (studentEvaluateList.size()>0){
//                for (int a=0;a<studentEvaluateList.size();a++){
//
//                    String [] indexScores=studentEvaluateList.get(a).getIndexscore().split(",");
////                    String indexScore=
//                    map1=new HashMap<String,Float>();
//                    for (int b=0;b<indexScores.length;b++){
//
//                        String [] xx=indexScores[b].split("!");
//                        String indexLabel=xx[1];
//                        float score=Float.parseFloat(xx[2]);
//                        System.out.println(indexLabel+"-----"+score);
//                        map1.put(indexLabel, score);
//                    }
//                    mapList.add(map1);
//
//                }
//                Map<Object, List> map2 = new HashMap<Object, List>();
//                for (Map m : mapList) {
//                    Iterator it = m.keySet().iterator();
//                    while (it.hasNext()) {
//                        Object key = it.next();
//                        if (!map2.containsKey(key)) {
//                            List<Object> newList = new ArrayList<Object>();
//                            newList.add(m.get(key));
//                            map2.put(key, newList);
//                        } else {
//                            map2.get(key).add(m.get(key));
//                        }
//                    }
//                }
////                map2
//
//                List<Map> mapList1=new ArrayList<Map>();
//                for (Map.Entry entry : map2.entrySet()) {
//                    Map<String,Object> map3=new HashMap<String,Object>();
////                    System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
//                    Float scoreNum=0f;
//                    List list=(List)entry.getValue();
//                    for (int i=0;i<list.size();i++){
//                        scoreNum+=(Float)list.get(i);
//                    }
//                    float scoreAvg = (float)(Math.round(scoreNum/list.size()*100))/100;
//                    System.out.println(scoreNum+"得分："+scoreAvg);
//                    map3.put("indexName",entry.getKey());
//                    map3.put("score",scoreAvg);
//                    mapList1.add(map3);
//                }
//                map.put("code",200);
//                map.put("message","查询学生统计结果成功");
//                map.put("data",mapList1);
//            }else {
//                map.put("code",201);
//                map.put("message","查询无结果");
//                map.put("data",null);
//            }
//
//
//        }else if (statisticsType.equals("colleagueEvaluate")){//同事评
//
//            System.out.println("进入同事评");
//            ColleagueEvaluate colleagueEvaluate=new ColleagueEvaluate();
//            colleagueEvaluate.setColleaguename(collegeName);
//            List<ColleagueEvaluate> colleagueEvaluateList=leadershipService.selectAllColleagueEvaluate(colleagueEvaluate);
//            Map<String,Object> map1=null;
//            List<Map> mapList=new ArrayList<Map>();
//            System.out.println("查出来的长度："+colleagueEvaluateList.size());
//            if (colleagueEvaluateList.size()>0){
//                for (int a=0;a<colleagueEvaluateList.size();a++){
//
//                    String [] indexScores=colleagueEvaluateList.get(a).getIndexscore().split(",");
////                    String indexScore=
//                    map1=new HashMap<String,Object>();
//                    for (int b=0;b<indexScores.length;b++){
//
//                        String [] xx=indexScores[b].split("!");
//                        String indexLabel=xx[1];
//                        float score=Float.parseFloat(xx[2]);
//                        System.out.println(indexLabel+"-----"+score);
//                        map1.put(indexLabel, score);
//                    }
//                    mapList.add(map1);
//
//                }
//                Map<Object, List> map2 = new HashMap<Object, List>();
//                for (Map m : mapList) {
//                    Iterator it = m.keySet().iterator();
//                    while (it.hasNext()) {
//                        Object key = it.next();
//                        if (!map2.containsKey(key)) {
//                            List<Object> newList = new ArrayList<Object>();
//                            newList.add(m.get(key));
//                            map2.put(key, newList);
//                        } else {
//                            map2.get(key).add(m.get(key));
//                        }
//                    }
//                }
////                map2
//
//                List<Map> mapList1=new ArrayList<Map>();
//                for (Map.Entry entry : map2.entrySet()) {
//                    Map<String,Object> map3=new HashMap<String,Object>();
////                    System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
//                    Float scoreNum=0f;
//                    List list=(List)entry.getValue();
//                    for (int i=0;i<list.size();i++){
//                        scoreNum+=(Float)list.get(i);
//                    }
//                    float scoreAvg = (float)(Math.round(scoreNum/list.size()*100))/100;
//                    System.out.println(scoreNum+"得分："+scoreAvg);
//                    map3.put("indexName",entry.getKey());
//                    map3.put("score", scoreAvg);
//                    mapList1.add(map3);
//                }
//                map.put("code",200);
//                map.put("message","查询同事统计结果成功");
//                map.put("data",mapList1);
//            }else {
//                map.put("code",201);
//                map.put("message","查询无结果");
//                map.put("data",null);
//            }
//
//        }else if (statisticsType.equals("supervisorEvaluate")){//督导评
//
//            System.out.println("进入督导评");
//            SupervisorEvaluate supervisorEvaluate=new SupervisorEvaluate();
//            supervisorEvaluate.setColleaguename(collegeName);
//            List<SupervisorEvaluate> supervisorEvaluateList=leadershipService.selectAllSupervisorEvaluate(supervisorEvaluate);
//            Map<String,Object> map1=null;
//            List<Map> mapList=new ArrayList<Map>();
//            System.out.println("查出来的长度："+supervisorEvaluateList.size());
//            if (supervisorEvaluateList.size()>0){
//                for (int a=0;a<supervisorEvaluateList.size();a++){
//
//                    String [] indexScores=supervisorEvaluateList.get(a).getIndexscore().split(",");
////                    String indexScore=
//                    map1=new HashMap<String,Object>();
//                    for (int b=0;b<indexScores.length;b++){
//
//                        String [] xx=indexScores[b].split("!");
//                        String indexLabel=xx[1];
//                        float score=Float.parseFloat(xx[2]);
//                        System.out.println(indexLabel+"-----"+score);
//                        map1.put(indexLabel, score);
//                    }
//                    mapList.add(map1);
//
//                }
//                Map<Object, List> map2 = new HashMap<Object, List>();
//                for (Map m : mapList) {
//                    Iterator it = m.keySet().iterator();
//                    while (it.hasNext()) {
//                        Object key = it.next();
//                        if (!map2.containsKey(key)) {
//                            List<Object> newList = new ArrayList<Object>();
//                            newList.add(m.get(key));
//                            map2.put(key, newList);
//                        } else {
//                            map2.get(key).add(m.get(key));
//                        }
//                    }
//                }
////                map2
//
//                List<Map> mapList1=new ArrayList<Map>();
//                for (Map.Entry entry : map2.entrySet()) {
//                    Map<String,Object> map3=new HashMap<String,Object>();
////                    System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
//                    Float scoreNum=0f;
//                    List list=(List)entry.getValue();
//                    for (int i=0;i<list.size();i++){
//                        scoreNum+=(Float)list.get(i);
//                    }
//                    float scoreAvg = (float)(Math.round(scoreNum/list.size()*100))/100;
//                    System.out.println(scoreNum+"得分："+scoreAvg);
//                    map3.put("indexName",entry.getKey());
//                    map3.put("score", scoreAvg);
//                    mapList1.add(map3);
//                }
//                map.put("code",200);
//                map.put("message","查询督导统计结果成功");
//                map.put("data",mapList1);
//            }else {
//                map.put("code",201);
//                map.put("message","查询无结果");
//                map.put("data",null);
//            }
//
//        }else{
//            map.put("code",202);
//            map.put("message","传入评价类型错误");
//            map.put("data",null);
//        }
//
//    return map;
//    }
//
//
    /**
     * 领导端统计问卷（除就业问卷外）
     * @param request
     * @return
     */
    @RequestMapping(value = "questionnaireLeaderStatistics")
    public synchronized @ResponseBody Map<String,Object> questionnaireLeaderStatistics(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<String, Object>();

//        int questionnaireId=Integer.parseInt(request.getParameter("questionnaireId"));//问卷id
        String questionnaireExplain=request.getParameter("questionnaireExplain");//问卷说明
//        System.out.println("接收到的说明："+questionnaireExplain);

        String teacherId=request.getParameter("teacherId");
//        System.out.println(teacherId);
        Integer roleId = Integer.parseInt(request.getParameter("roleId"));
        String token=request.getParameter("token");

        TeacherData teacherData;
        teacherData = (TeacherData) tokenController.tokenLead(teacherId, roleId, token);
        if (teacherData==null){
            map.put("code", 203);
            map.put("message", "您暂无权限做此操作");
//            map.put("data", null);
            return map;
        }

        Questionnaire questionnaire=new Questionnaire();
        questionnaire.setQuestionnaireexplain(questionnaireExplain);

//        System.out.println("进入1");
        List<Questionnaire> questionnaireList=questionnaireService.selectAllQuestionnaire(questionnaire);
//        System.out.println("进入2：查出数据数"+questionnaireList.size());
        if (questionnaireList.size()>0){

//            System.out.println("进入3");
            List<Map> mapList=new ArrayList<Map>();
            List list=new ArrayList();
            List<QuestionnaireResult> questionnaireResults=null;
            for (int a=0;a<questionnaireList.size();a++){

//                questionnaireResults=new ArrayList<QuestionnaireResult>();
//                System.out.println("进入for");
//                System.out.println("问卷id："+questionnaireList.get(a).getQuestionnaireid());
                int questionnaireId=questionnaireList.get(a).getQuestionnaireid();

                QuestionnaireStatistical questionnaireStatistical=questionnaireService.selectStatistical(questionnaireId);
                questionnaireResults=questionnaireService.selectQuestionnaireResult(questionnaireId);

                if (questionnaireStatistical!=null&&questionnaireResults!=null){

                    if (questionnaireStatistical.getDetailedstatistical()!=null){
                        list.add(questionnaireStatistical.getDetailedstatistical());
                    }

                }else {
                    map.put("code",202);
                    map.put("message", "获取题目失败");
//                    map.put("data",null);
                }
            }
//            System.out.println("list的长度：" + list.size());

            Map<String,Integer> map1=new HashMap<String,Integer>();
            for (int b=0;b<list.size();b++){

                String[] questionnaireStatisticals=list.get(b).toString().split("!!");

                for (int c=0;c<questionnaireStatisticals.length;c++){

                    String topic=questionnaireStatisticals[c].split("_")[0];//题目，格式：题序号!选项 或 题序号!选项!分数
                    int statisticNum=Integer.parseInt(questionnaireStatisticals[c].split("_")[1]);//选项选择的人数
                    if (map1.containsKey(topic)) {
                        map1.put(topic, map1.get(topic) + statisticNum);
                    }else {
                        map1.put(topic,statisticNum);
                    }

                }
            }
            List<Map> mapList1=new ArrayList<Map>();
            List<Map> mapList2=new ArrayList<Map>();
            for (String key : map1.keySet()) {
//                System.out.println("key= "+ key + " and value= " + map1.get(key));
                String[] keys=key.split("!");
                if (keys.length==2){//选择题

                    int questionNum=Integer.parseInt(keys[0]);//问题序号
                    String option=keys[1];//选项
                    int statisticNum=map1.get(key);
                    Map<Integer,String> map2=new HashMap<Integer,String>();
                    map2.put(questionNum,option+"_"+statisticNum);

                    mapList1.add(map2);

                }else if (keys.length==3){//打分题
                    Map<Integer,String> map2=new HashMap<Integer,String>();
                    int questionNum=Integer.parseInt(keys[0]);
                    String opStist1=keys[1];
                    float score=Float.parseFloat(keys[2]);
                    int statisticNum=map1.get(key);
                    float sum=score*statisticNum;
                    map2.put(questionNum,opStist1+"_"+sum+"=="+statisticNum);//格式：选项_总分==人数

                    mapList2.add(map2);

                }else{
                    //错误
                }

            }
            Map<Object, List> map3 = new HashMap<Object, List>();
            for (Map m : mapList1) {
                Iterator it = m.keySet().iterator();
                while (it.hasNext()) {
                    Object key = it.next();
                    if (!map3.containsKey(key)) {
                        List<Object> newList = new ArrayList<Object>();
                        newList.add(m.get(key));
                        map3.put(key, newList);//{题序号：[选项1_人数，选项2_人数。。]}
                    } else {
                        map3.get(key).add(m.get(key));
                    }
                }
            }
            List<Map> list2=null;
            for (Object key:map3.keySet()){
                List value=map3.get(key);
                String option="";
                float stisNum=0;
                list2 = new ArrayList<Map>();
                for (int x=0;x<questionnaireResults.size();x++){
                    Map<String,Object> map4=new HashMap<String,Object>();
                    if (key==questionnaireResults.get(x).getQuestionnumber()){
//                                  System.out.println("进入匹配："+key);
                        String questionContent=questionnaireResults.get(x).getQuestioncontent();//题目
                        String problemTypes=questionnaireResults.get(x).getProblemtypes();//问题类型
                        String questionState=questionnaireResults.get(x).getQuestionstate();//问题头
                        String questionDescribe=questionnaireResults.get(x).getQuestiondescribe();//问题描述

                        String[] ops = questionnaireResults.get(x).getOptions().split("!!");
                        String[] optionsDescribes = questionnaireResults.get(x).getOptionsdescribe().split("!!");
                        Map<String,Object> map5=null;
                        String str2="";
                        List<String> list3=new ArrayList<String>();
                        for (int y = 0; y < ops.length; y++) {

                            for (int a=0;a<value.size();a++) {

                                option = value.get(a).toString().split("_")[0];
                                list3.add(option);
                                stisNum = Integer.parseInt(value.get(a).toString().split("_")[1]);
                                //                                System.out.println("option："+option+"   "+stisNum);
//                                          System.out.println("进入for:" + option+"======="+ops[y]);

                                map5=new HashMap<String,Object>();
                                if (option.equals(ops[y]) ) {
//                                              System.out.println("进入if");
                                    String optionsDescrib = optionsDescribes[y];
//                                              System.out.println(key + "-----" + optionsDescribe);
                                    map5.put("option", option);
                                    map5.put("optionsDescribe", optionsDescrib);
                                    map5.put("stisNum",stisNum);

                                    list2.add(map5);
                                }
                            }
                        }
                        String optionsDescribe="";
                        Map<String,Object> map6=null;

                        for(int y=0;y<ops.length;y++){
                            map6=new HashMap<String,Object>();
                            Boolean exists = (list3).contains(ops[y]);
                            if (exists) {

                            }else {
                                str2 = ops[y];
                                optionsDescribe = optionsDescribes[y];
//                                System.out.println("没答的选项的描述："+optionsDescribe);
//                                          System.out.println(key + "-----" + optionsDescribe);
                                if (str2!=null&&!str2.equals("")){
                                    map6.put("option", str2);
                                    map6.put("optionsDescribe", optionsDescribe);
                                    map6.put("stisNum",0);
                                    list2.add(map6);
                                }
                            }
                        }

//                                  System.out.println("list2："+list2);
                        map4.put("questionNum", key);
                        map4.put("questionTypes", problemTypes);
                        map4.put("questionContent",questionContent);
                        map4.put("questionState",questionState);
                        map4.put("questionDescribe",questionDescribe);
                        map4.put("statistical",list2);
                        mapList.add(map4);
                    }
                }
            }
            Map<Object, List> map8 = new HashMap<Object, List>();
            for (Map m : mapList2) {
                Iterator<Object> it = m.keySet().iterator();
                while (it.hasNext()) {
                    Object key = it.next();
                    if (!map8.containsKey(key)) {
                        List newList = new ArrayList();
                        newList.add(m.get(key));
                        map8.put(key, newList);//{题序号：[选项1_总分==人数，选项2_总分==人数。。]}
                    } else {
                        map8.get(key).add(m.get(key));
                    }
                }
            }
            for (Object key:map8.keySet()){
                List value=map8.get(key);
                String option="";
                int stisNum=0;
                list2 = new ArrayList<Map>();
                for (int x=0;x<questionnaireResults.size();x++){
                    Map<String,Object> map4=new HashMap<String,Object>();
                    if (key==questionnaireResults.get(x).getQuestionnumber()){
//                                  System.out.println("进入匹配："+key);
                        String questionContent=questionnaireResults.get(x).getQuestioncontent();
                        String problemTypes=questionnaireResults.get(x).getProblemtypes();
                        String questionState=questionnaireResults.get(x).getQuestionstate();
                        String questionDescribe=questionnaireResults.get(x).getQuestiondescribe();

                        String[] ops = questionnaireResults.get(x).getOptions().split("!!");
                        String[] optionsDescribes = questionnaireResults.get(x).getOptionsdescribe().split("!!");
                        Map<String,Object> map5=null;
                        String str2="";
                        List<String> list3=new ArrayList<String>();
                        List<String> list6=new ArrayList<String>();


                            List l=new ArrayList();
                            String option1="";
//                        System.out.println("value的长度：" + value.size());
                            for (int w = 0; w < value.size(); w++) {
                                List<String> list1=new ArrayList<String>();
                                //每一次由底至上地上升
//                                System.out.println("value："+value.get(w));

                                option1 = value.get(w).toString().split("_")[0];
                                String stisNum1 = value.get(w).toString().split("_")[1];
                                for (int e = value.size() - 1; e > w; e--) {
                                    String option2 = value.get(e).toString().split("_")[0];//value格式：题序号_分数==所选人数
                                    String stisNum2 = value.get(e).toString().split("_")[1];
                                    if (option1.equals(option2)) {
                                        list1.add(stisNum2);
//                                        l.add(option2);
                                        value.remove(e);
                                    }
                                }
                                list1.add(stisNum1);
//                                l.add(option1);

                                float sumScore = 0;
                                int sumNum = 0;
//                                System.out.println("list1的的的的长度：" + list1.size());
                                for (int r = 0; r < list1.size(); r++) { //格式：分数==所选人数

                                    float score = Float.parseFloat(list1.get(r).split("==")[0]);
                                    int num = Integer.parseInt(list1.get(r).split("==")[1]);
//                                    System.out.println("分数：" + score + "  人数：" + num);
                                    sumScore += score;
                                    sumNum += num;
                                }
//                                System.out.println("总分：" + sumScore + "   总人数：" + sumNum);
                                float avgScore = (float) (Math.round(sumScore / sumNum * 10000)) / 10000;
//                                System.out.println("题序号：" + option1 + "  得分：" + avgScore);
                                list6.add(option1 + "_" + avgScore);
                            }

//                            System.out.println("list6的长度："+list6.size());
                        for (int y = 0; y < ops.length; y++) {
                            for (int a=0;a<list6.size();a++) {

                                option = list6.get(a).split("_")[0];
                                list3.add(option);
                                float stisNums=Float.parseFloat(list6.get(a).split("_")[1]);
//                                System.out.println(option+" 得到的分数："+stisNums);

//                                            stisNum = Integer.parseInt(value.get(a).toString().split("_")[1]);
                                //                                System.out.println("option："+option+"   "+stisNum);
//                                          System.out.println("进入for:" + option+"======="+ops[y]);

                                map5=new HashMap<String,Object>();
                                if (option.equals(ops[y]) ) {
//                                              System.out.println("进入if");
                                    String optionsDescrib = optionsDescribes[y];
//                                              System.out.println(key + "------" + optionsDescribe);
                                    map5.put("option", option);
                                    map5.put("optionsDescribe", optionsDescrib);
                                    map5.put("stisNum",stisNums);

                                    list2.add(map5);
                                }
                            }
                        }
                        String optionsDescribe="";
                        Map<String,Object> map6=null;

                        for(int y=0;y<ops.length;y++){
                            map6=new HashMap<String,Object>();
                            Boolean exists = (list3).contains(ops[y]);
                            if (exists) {

                            }else {
                                str2 = ops[y];
                                optionsDescribe = optionsDescribes[y];
//                                System.out.println("没答的选项的描述："+optionsDescribe);
//                                          System.out.println(key + "-----" + optionsDescribe);
                                if (str2!=""&&str2!=null){
                                    map6.put("option", str2);
                                    map6.put("optionsDescribe", optionsDescribe);
                                    map6.put("stisNum",0);
                                    list2.add(map6);
                                }
                            }
                        }
//                                  System.out.println("list2："+list2);
                        map4.put("questionNum", key);
                        map4.put("questionTypes", problemTypes);
                        map4.put("questionContent",questionContent);
                        map4.put("questionState",questionState);
                        map4.put("questionDescribe",questionDescribe);
                        map4.put("statistical",list2);
                        mapList.add(map4);
                    }
                }
            }
//            System.out.println("maplist的长度：" + mapList.size());
            map.put("code",200);
            map.put("message","查询统计结果成功");
            map.put("data",mapList);
        } else {
            map.put("code",201);
            map.put("message","无该类型问卷");
//            map.put("data",null);
        }

        return map;
    }


    /**
     * 就业问卷统计
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "employmentQuestionnaireStatistics")
    public synchronized @ResponseBody Map<String,Object> reviewCompletion(HttpServletRequest request)throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        List<Map> mapList=new ArrayList<Map>();

        String teacherId=request.getParameter("teacherId");
//        System.out.println(teacherId);
        Integer roleId = Integer.parseInt(request.getParameter("roleId"));
        String token=request.getParameter("token");

        TeacherData teacherData;
        teacherData = (TeacherData) tokenController.tokenLead(teacherId, roleId, token);
        if (teacherData==null){
            map.put("code", 203);
            map.put("message", "您暂无权限做此操作");
//            map.put("data", null);
            return map;
        }

        List<EmploymentQuestStatistical> employmentQuestStatisticalList=employmentService.selectLatestStatisical();

        if (employmentQuestStatisticalList.size()>0){

            for (int a=0;a<employmentQuestStatisticalList.size();a++){
                Map<String, Object> map1 = new HashMap<String, Object>();
                map1.put("questionNum",employmentQuestStatisticalList.get(a).getQuestionnum());//序号
                map1.put("statisticalPhoto",employmentQuestStatisticalList.get(a).getStatisticalphoto());//统计图
                map1.put("questionState",employmentQuestStatisticalList.get(a).getQuestionstate());//统计图说明,头
                map1.put("questionDescribe",employmentQuestStatisticalList.get(a).getQuestiondescribe());//统计图描述
                map1.put("numberOfPeople",employmentQuestStatisticalList.get(a).getNumberofpeople());//此题统计的总人数

                mapList.add(map1);
            }
            map.put("code",200);
            map.put("message","查询统计结果成功");
            map.put("data",mapList);
        }else {
            map.put("code",201);
            map.put("message","无就业问卷统计");
//            map.put("data",null);
        }

        return map;
    }

}
